/**
  * Copyright (c) CSIRO Australia, 2009
  *
  * @author $Author: jia020 $
  * @version $Id: HeaderPanel.java 643 2009-05-20 00:20:55Z jia020 $
  */
package au.csiro.nt.pdsp.client;

import com.gwtext.client.widgets.Panel;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.i18n.client.HasDirection.Direction;

/**
 * class to create Header panel. 
 *
 */
public class HeaderPanel extends Panel {
	private HTML signInLink = new HTML("<a href='javascript:;'>Sign Out</a>");
	private HTML aboutLink = new HTML("<a href='javascript:;'>About</a>");

	public HeaderPanel() {
		DockPanel dockPanel = new DockPanel();
		dockPanel.setSize("100%", "100%");
		Image image = new Image("images/CSIRO-logo.png");
		image.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
			}
		});
		image.setPixelSize(203, 64);
		dockPanel.add(image, DockPanel.CENTER);
		// this.add(dockPanel);
		VerticalPanel inner = new VerticalPanel();
		inner.setHeight("64px");
		inner.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
		
		HTML html = new HTML("<b>Welcome back," + GlobalVars.getInstance().userid + ":" + GlobalVars.getInstance().role + "</b>");
		//HTML html = new HTML("<b>Welcome back,foo@sample.com</b>");
		html.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		html.setStyleName("IndividaulPanel");
		inner.add(html);

		HorizontalPanel links = new HorizontalPanel();
		links.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		links.setSpacing(4);
//		ExternalHyperlink logout = new ExternalHyperlink(" Sign out", GWT.getHostPageBaseURL() + "j_logout");
		Hyperlink logout = new Hyperlink("Sign out", "home");//GWT.getHostPageBaseURL() + "j_logout");
		String styleName = null;
		String role = GlobalVars.getInstance().role;
		if (role.equalsIgnoreCase(PdspConst.ROLE_INDIVIDUAL))
			styleName = "IndividaulPanel";
		else if(role.equalsIgnoreCase(PdspConst.ROLE_ORGANISATION))
			styleName = "OrganisationPanel";	
		else if(role.equalsIgnoreCase(PdspConst.ROLE_ADMIN))
			styleName = "AdministratorPanel";			
		logout.setStyleName(styleName);		
		aboutLink.setStyleName(styleName);
		links.add(logout);
		links.add(aboutLink);
		inner.add(links);

		dockPanel.setCellHorizontalAlignment(image, DockPanel.ALIGN_LEFT);
		// dockPanel.setCellHorizontalAlignment(inner, DockPanel.ALIGN_RIGHT);

		dockPanel.add(inner, DockPanel.EAST);
		dockPanel.setCellHorizontalAlignment(inner,
				HasHorizontalAlignment.ALIGN_RIGHT);
		// signInLink.addClickHandler(this);
		// aboutLink.addClickHandler(this);
		this.add(dockPanel);

	}

}
